import {ADD_REMINDER,DEL_REMINDER,CLAEN_REMINDER} from '@/constants';
import { get_items,save_item,clean_item,del_item } from '@/utils/saveLocal';
const todoList = (state=[],action={}) => {
  state = get_items();
  switch (action.type){
    case ADD_REMINDER:
    save_item({
      id: state.length + 1,
      content: action.content,
      time: action.time
    });
    return [
    {
      id: state.length + 1,
      content: action.content,
      time: action.time
    },
    ...state
    ];
    case DEL_REMINDER:
    state = state.filter(item => item.id !== action.id);
    del_item(state);
    return state;
    case CLAEN_REMINDER:
    clean_item();
    return state = [];
    default:
    return state;
  }
};
export default todoList;